#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qcombobox.h>
#include <qgroupbox.h>
#include <qpushbutton.h>
#include <qlabel.h>

#include "dev_lsg_cc.h"
#include "dev_reader_hf.h"
#include "dev_reader_uhf.h"
#include "QListWidgetItem"
#include "invenparams.h"
#include "scan_record.h"
#include "MyCriticalSection.h"

namespace Ui {
class MainWindow;
}

#define DEVICE_TYPE_HF 0
#define DEVICE_TYPE_UHF 1
#define DEVICE_TYPE_LSGCC 2


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    const static int UHF_TAG_MAX_WORD_NUMBER = 128;//RFU/EPC/TID/USER max use words size
    InvenParams* invenParams = NULL;
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void paintEvent(QPaintEvent *e);
private:
    bool loaded=false;
    void set_info(QString str,bool success=true);

public slots:
    void slot_inventory_data_hf(int tag_count,vector<CTag_HF> tags,int use_time,int loop_count);
    void slot_inventory_data_uhf(int tag_count,vector<CTag_UHF> tags,int use_time,int loop_count);
    void slot_inventory_end_loop(int iret);//stop inventory ,thread ended

    void slot_scan_mode_data(int tag_count,vector<CScan_Record> tags,int use_time,int loop_count);
    void slot_scan_mode_end_loop(int iret);//stop scan mode ,thread ended

private slots:
    void on_btn_open_clicked();

    void on_btn_close_clicked();

    void on_cmb_commtype_currentIndexChanged(int index);

    void on_btn_getinfo_clicked();

    void on_cmb_usb_opentype_currentIndexChanged(int index);

    void on_btn_inventory_start_clicked();

    void on_btn_inventory_stop_clicked();

    void on_cmb_access_tags_currentIndexChanged(int index);

    void on_lw_ants_itemPressed(QListWidgetItem *item);

    void on_myTabs_currentChanged(int index);

    void on_tbw_inventory_tags_cellDoubleClicked(int row, int column);

    void on_tbw_inventory_tags_cellClicked(int row, int column);

    void on_btn_access_get_status_clicked();

    void on_btn_access_write_afi_clicked();


    void on_btn_access_read_block_clicked();

    void on_btn_access_write_block_clicked();

    void on_btn_access_open_eas_clicked();

    void on_btn_access_close_eas_clicked();

    void on_btn_access_get_eas_clicked();

    void on_cmb_rdtype_currentIndexChanged(int index);

    void on_btn_access_write_mem_clicked();

    void on_btn_access_read_mem_clicked();

    void on_btn_access_kill_clicked();

    void on_btn_inventory_setting_clicked();


    void on_btn_uhf_access_setting_clicked();

    //LSG CONTROL CENTER
    void create_ir_trigger_view();
    void init_lsgcc_sgl_door();

    void get_selected_outputs(BYTE* outputs,int* len);

    void show_lsgcc_get_rcd();
    void on_btn_sgl_door_start_alarm_clicked();

    void on_btn_sgl_door_set_atmo_light_clicked();

    void on_cmb_sgl_door_output_mode_currentIndexChanged(int index);

    void on_btn_sgl_door_set_output_clicked();

    void on_btn_sgl_door_get_ir_trigger_counter_clicked();

    void on_btn_lsgcc_people_count_init_clicked();

    void on_btn_lsgcc_people_count_get_clicked();

    void on_btn_lsgcc_systime_get_clicked();

    void on_btn_lsgcc_systime_set_clicked();

    void on_btn_lsgcc_get_records_clicked();

    void on_lw_sgl_door_output_itemPressed(QListWidgetItem *item);


    void on_btn_scan_mode_start_clicked();

    void on_btn_scan_mode_stop_clicked();

    void on_btn_scan_mode_clear_clicked();

    void on_btn_inventory_clear_clicked();

private:
    Ui::MainWindow *ui;

    /**
     * @brief m_rdr 读卡器操作类
     * reader oprate class
     */
    CAEDevice *m_rdr=NULL;
    QString RDType = QString("%1").arg("");
    int Device_Type = -1;//0:HF 1:UHF 2:LSGCC
    QComboBox* m_cmb_access;
    QPalette pltSuccess;
    QPalette pltFail;
    QLabel* m_lbl_info;
    QFrame* m_fra_access;
    void getConnectString(char *&connStr);
    void initControlData();//set combox item data
    void enableControls(bool opened, int comm_index);
    void enableCommGroup(bool opened, int comm_index);
    void refresh_uhf_pwds();
    void show_uhf_setting(int tab_index);
    void create_reader();
    void create_inventory_view();
    void create_scan_mode_view();
    void update_net_port();//更新网络端口
    void update_access_position();
    void bind_antennas();
    void get_selected_antennas(BYTE ants[], int &len);

    vector<CTag_HF> m_tags_hf;
    vector<CTag_UHF> m_tags_uhf;
    vector<CScan_Record> m_scan_records;
    int cur_tag_index=-1;
    void bind_access_tags(int tag_index);
    void setTagBlockNums(int block_nums);
    int get_tag_status(CTag &tag, char *&pOut);
    void setWidgetEnable(QWidget *m_wid,bool enable);
    CMyCriticalSection m_lock;
};

#endif // MAINWINDOW_H
